package com.sun.androidexerciseproject.function.model;

import org.json.JSONException;
import org.json.JSONObject;

import okhttp3.MediaType;
import okhttp3.RequestBody;

/**
 * Created by Administrator on 2017/12/6 0006.
 */

public class PayRequestParam extends RequestParam {
    private static final MediaType JSON
            = MediaType.parse("application/json; charset=utf-8");
    private final String KEY_APPID = "appId";
    private final String KEY_API_VER = "apiVer";
    private final String KEY_PAY_TYPE = "payType";
    private final String KEY_SCENCE = "scene";
    private final String KEY_TERMINAL = "terminal";
    private final String KEY_FMT = "fmt";
    private final String KEY_CHARSET = "charset";
    private final String KEY_SGN_TYPE = "sgnType";
    private final String KEY_MERCH_ORDR_NO = "merchOrdrNo";
    private final String KEY_TOT_ORDR_AMT = "totOrdrAmt";
    private final String KEY_NOTE_URL = "noteUrl";
    private final String KEY_RTN_URL = "rtnUrl";
    private final String KEY_TIME_STAMP = "timeStamp";
    private final String KEY_USR_NAME = "usrName";
    private final String KEY_EXT_PARM = "extParm";
    private final String KEY_SGN = "sgn";
    private PayParam mPayParam;
    private JSONObject mJSONObject;

    public PayRequestParam(PayParam param) {
        mPayParam = param;
        mJSONObject = new JSONObject();
        try {
            mJSONObject.put(KEY_APPID, mPayParam.getAppId());
            mJSONObject.put(KEY_API_VER, mPayParam.getApiVer());
            mJSONObject.put(KEY_PAY_TYPE, mPayParam.getPayType());
            mJSONObject.put(KEY_SCENCE, mPayParam.getScene());
            mJSONObject.put(KEY_TERMINAL, mPayParam.getTerminal());
            mJSONObject.put(KEY_FMT, mPayParam.getFmt());
            mJSONObject.put(KEY_CHARSET, mPayParam.getCharset());
            mJSONObject.put(KEY_SGN_TYPE, mPayParam.getSgnType());
            mJSONObject.put(KEY_MERCH_ORDR_NO, mPayParam.getMerchOrdrNo());
            mJSONObject.put(KEY_TOT_ORDR_AMT, mPayParam.getTotOrdrAmt());
            mJSONObject.put(KEY_NOTE_URL, mPayParam.getNoteUrl());
            mJSONObject.put(KEY_RTN_URL, mPayParam.getRtnUrl());
            mJSONObject.put(KEY_TIME_STAMP, mPayParam.getTimeStamp());
            mJSONObject.put(KEY_USR_NAME, mPayParam.getUsrName());
            mJSONObject.put(KEY_EXT_PARM, mPayParam.getExtParm());
//            mJSONObject.put(KEY_SGN, mPayParam.getSgn());
            mJSONObject.put("secretKey", "8A3F1E76C5A7BB0E1B26CBE1928AE17899C25B2651E38FE279B0F49F23CAFA9C");
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    @Override
    public RequestBody getRequestBody() {
        RequestBody body = RequestBody.create(JSON, mJSONObject.toString());
        return body;

    }

    public JSONObject getJSONObject() {
        return mJSONObject;
    }
}
